#!/bin/bash
# leebor
# 2017-11-1
# init ECS php-fpm.conf
# v1.0


INSTALL_DIR='/opt/php7'

function Change_www() {
	cd $INSTALL_DIR/etc/php-fpm.d/
	if [ -f www.conf ];then
	    mv www.conf www.conf-$(date +%Y%m%d-%H%M%S)
	fi
	echo "; changed by leebor at $(date)" >> www.conf
	egrep -v ';|^$' www.conf.default >> www.conf
	echo "pm = static" >> www.conf
	echo "pm.max_children = 60" >> www.conf
	echo "pm.max_requests = 500" >> www.conf
	echo "pm.status_path = /status" >> www.conf
	echo "ping.path = /ping" >> www.conf
	echo "access.log = log/$pool.access.log" >> www.conf
	echo 'access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' >> www.conf
	echo "slowlog = log/$pool.log.slow" >> www.conf
	echo "request_slowlog_timeout = 300" >> www.conf
	egrep -v ";|^$" www.conf
}

function Change_global() {
	cd $INSTALL_DIR/etc
	if [ -f php-fpm.conf ];then
	    mv php-fpm.conf php-fpm.conf-$(date +%Y%m%d-%H%M%S)
	fi
	echo "; Changed by leebor at $(date)" >> php-fpm.conf
	echo 
	echo 
	egrep -v ";|^$" php-fpm.conf.default >> php-fpm.conf
	if [ ! -f php-fpm.conf ];then echo "Error";exit;fi
	sed -i "/^include/i\pid = run/php-fpm\.pid" php-fpm.conf
	sed -i "/^include/i\error_log = log/php-fpm\.log" php-fpm.conf
	sed -i "/^include/i\log_level = notice" php-fpm.conf
	sed -i "/^include/i\daemonize = yes" php-fpm.conf
	egrep -v ";|^$" php-fpm.conf
}

Change_www
Change_global
